package com.dealglobe.feeder.bvd;

import com.bvdep.webservices.RemoteAccess;
import com.bvdep.webservices.RemoteAccessSoap;
import com.bvdep.webservices.SelectionResult;
import com.dealglobe.feeder.bvd.query.BvdQuery;
import com.dealglobe.feeder.bvd.query.BvdQueryExecutor;

public class App {

    /**
     * @param args
     */
    public static void main(String[] args) {
        int nrRecords = args.length > 0 ? Integer.parseInt(args[0]) : 100;
        RemoteAccessSoap ws = null;
        String sessionHandle =  null;
        try {
            RemoteAccess remoteAccess = new RemoteAccess();
            ws = remoteAccess.getRemoteAccessSoap();
            sessionHandle = ws.open("DealGlobeWS", "Il48GzeZ4");
            
            BvdQuery query = BvdQuery.newGetCommonCompanyDataByRegion("9XEGB");
            BvdQueryExecutor queryExecutor = new BvdQueryExecutor(ws, sessionHandle);
            SelectionResult selectionResult = queryExecutor.find(query);
            
            String data = queryExecutor.getData(query, selectionResult, nrRecords);
            System.out.println(data);
            
            query = BvdQuery.newGetFinancialCompanyDataByRegion("9XEGB");
            data = queryExecutor.getData(query, selectionResult, nrRecords);
            System.out.println(data);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (sessionHandle != null) {
                ws.close(sessionHandle);
            }
        }       
    }
}
